﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Game.Data.Factory;
using Game.IData;
using Game.Kernel;
using Game.Utils;
using Game.Entity.Treasure;
using System.Data;
using Game.Data;
using System.Data.Common;
using System.Web;

namespace Game.Facade
{
    /// <summary>
    /// 金币库外观
    /// </summary>
    public class TreasureFacade
    {
        #region Fields

        private ITreasureDataProvider treasureData;

        #endregion

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        public TreasureFacade()
        {
            treasureData = ClassFactory.GetITreasureDataProvider();
        }

        /// <summary>
        /// 带参构造函数
        /// </summary>
        /// <param name="kindID"></param>
        public TreasureFacade( int kindID )
        {
            treasureData = ClassFactory.GetITreasureDataProvider(kindID);
        }
        #endregion

        #region 在线充值

        /// <summary>
        /// 生成订单
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public Message RequestOrder(OnLineOrder orderInfo, int productType, int appID)
        {
            return treasureData.RequestOrder(orderInfo, productType, appID);
        }

        /// <summary>
        /// 生成房卡订单
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public Message RequestOrderFK(OnLineOrder orderInfo, int configID)
        {
            return treasureData.RequestOrderFK(orderInfo, configID);
        }

        /// <summary>
        /// 写天天付返回记录
        /// </summary>
        /// <param name="returnKQ"></param>
        public void WriteReturnDayDetail( ReturnDayDetailInfo returnDay )
        {
            treasureData.WriteReturnDayDetail( returnDay );
        }

        /// <summary>
        /// 写快钱返回记录
        /// </summary>
        /// <param name="returnKQ"></param>
        public void WriteReturnKQDetail( ReturnKQDetailInfo returnKQ )
        {
            treasureData.WriteReturnKQDetail( returnKQ );
        }

        /// <summary>
        /// 写电话充值返回记录
        /// </summary>
        /// <param name="returnKQ"></param>
        public Message WriteReturnVBDetail( ReturnVBDetailInfo returnVB )
        {
            return treasureData.WriteReturnVBDetail( returnVB );
        }

        /// <summary>
        /// 写易宝返回记录
        /// </summary>
        /// <param name="returnYB"></param>
        public Message WriteReturnYBDetail( ReturnYPDetailInfo returnYB )
        {
            return treasureData.WriteReturnYBDetail( returnYB );
        }

        /// <summary>
        /// 在线充值
        /// </summary>
        /// <param name="olDetial"></param>
        /// <returns></returns>
        public Message FilliedOnline( ShareDetialInfo olDetial, int isVB )
        {
            return treasureData.FilliedOnline( olDetial, isVB );
        }

        /// <summary>
        /// 在线房卡充值
        /// </summary>
        /// <param name="olDetial"></param>
        /// <returns></returns>
        public Message FilliedOnlineFK(ShareDetialInfo olDetial, int isVB)
        {
            return treasureData.FilliedOnlineFK(olDetial, isVB);
        }

        /// <summary>
        /// 苹果充值
        /// </summary>
        /// <param name="olDetial"></param>
        /// <returns></returns>
        public Message FilliedApp(ShareDetialInfo olDetial, string productID)
        {
            return treasureData.FilliedApp(olDetial, productID);
        }

        /// <summary>
        /// 手游充值
        /// </summary>
        /// <param name="olDetial"></param>
        /// <returns></returns>
        public Message FilliedMobile(ShareDetialInfo olDetial)
        {
            return treasureData.FilliedMobile(olDetial);
        }

        /// <summary>
        /// 实卡充值
        /// </summary>
        /// <param name="associator"></param>
        /// <param name="operUserID"></param>
        /// <param name="accounts"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public Message FilledLivcard( ShareDetialInfo detialInfo, string password )
        {
            return treasureData.FilledLivcard( detialInfo, password );
        }

        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="orderID"></param>
        /// <returns></returns>
        public OnLineOrder GetOnlineOrder( string orderID )
        {
            return treasureData.GetOnlineOrder( orderID );
        }

        /// <summary>
        /// 获取苹果产品列表
        /// </summary>
        /// <returns></returns>
        public DataSet GetAppList()
        {
            return treasureData.GetAppList();
        }

        /// <summary>
        /// 获取苹果产品列表
        /// </summary>
        /// <returns></returns>
        public DataSet GetAppListByTagID( int tagID )
        {
            return treasureData.GetAppListByTagID( tagID );
        }

        /// <summary>
        /// 获取产品信息
        /// </summary>
        /// <param name="ProductID"></param>
        /// <returns></returns>
        public DataSet GetAppInfoByProductID( string productID )
        {
            return treasureData.GetAppInfoByProductID( productID );
        }

        /// <summary>
        /// 写苹果返回记录
        /// </summary>
        /// <param name="detialInfo"></param>
        /// <param name="receipt"></param>
        public void WriteReturnAppDetail( ShareDetialInfo detialInfo, AppReceiptInfo receipt )
        {
            treasureData.WriteReturnAppDetail( detialInfo, receipt );
        }

        /// <summary>
        /// 获取充值面额列表
        /// </summary>
        /// <param name="cardID"></param>
        /// <returns></returns>
        public DataSet GetPayQuotaList(int cardID)
        {
            return treasureData.GetPayQuotaList(cardID);
        }
        #endregion

        #region 充值记录

        /// <summary>
        /// 充值记录
        /// </summary>
        /// <param name="whereQuery"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagerSet GetPayRecord( string whereQuery, int pageIndex, int pageSize )
        {
            return treasureData.GetPayRecord( whereQuery, pageIndex, pageSize );
        }

        /// <summary>
        /// 充值记录
        /// </summary>
        /// <param name="whereQuery"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagerSet GetPayRecord(string whereQuery, int pageIndex, int pageSize, string[] returnField = null)
        {
            return treasureData.GetPayRecord(whereQuery, pageIndex, pageSize, returnField);
        }

        #endregion

        #region 推广中心

        /// <summary>
        /// 获取用户推广信息
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public Message GetUserSpreadInfo( int userID )
        {
            return treasureData.GetUserSpreadInfo( userID );
        }

        /// <summary>
        /// 用户推广结算信息
        /// </summary>
        /// <param name="balance"></param>
        /// <param name="userID"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public Message GetUserSpreadBalance( int balance, int userID, string ip )
        {
            return treasureData.GetUserSpreadBalance( balance, userID, ip );
        }

        /// <summary>
        /// 推广记录
        /// </summary>
        /// <param name="whereQuery"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagerSet GetSpreaderRecord( string whereQuery, int pageIndex, int pageSize )
        {
            return treasureData.GetSpreaderRecord( whereQuery, pageIndex, pageSize );
        }

        /// <summary>
        /// 单个用户下所有被推荐人的推广信息
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public DataSet GetUserSpreaderList( int userID, int pageIndex, int pageSize )
        {
            return treasureData.GetUserSpreaderList( userID, pageIndex, pageSize );
        }

        /// <summary>
        /// 获取单个结算总额
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public long GetUserSpreaderTotal( string sWhere )
        {
            return treasureData.GetUserSpreaderTotal( sWhere );
        }

        /// <summary>
        /// 获取推广配置实体
        /// </summary>
        /// <returns></returns>
        public GlobalSpreadInfo GetGlobalSpreadInfo()
        {
            return treasureData.GetGlobalSpreadInfo();
        }

        #endregion

        #region 银行操作

        /// <summary>
        /// 金币存入
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="TradeScore"></param>
        /// <param name="minTradeScore"></param>
        /// <param name="clientIP"></param>
        /// <param name="note"></param>
        /// <returns></returns>
        public Message InsureIn( int userID, Int64 TradeScore, string clientIP, string note )
        {
            return treasureData.InsureIn( userID, TradeScore, clientIP, note );
        }

        /// <summary>
        /// 金币取出
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="insurePass"></param>
        /// <param name="TradeScore"></param>
        /// <param name="minTradeScore"></param>
        /// <param name="clientIP"></param>
        /// <param name="note"></param>
        /// <returns></returns>
        public Message InsureOut( int userID, string insurePass, Int64 TradeScore, string clientIP, string note )
        {
            return treasureData.InsureOut( userID, insurePass, TradeScore, clientIP, note );
        }

        /// <summary>
        /// 金币转账
        /// </summary>
        /// <param name="srcUserID"></param>
        /// <param name="insurePass"></param>
        /// <param name="dstUserID"></param>
        /// <param name="TradeScore"></param>
        /// <param name="minTradeScore"></param>
        /// <param name="clientIP"></param>
        /// <param name="note"></param>
        /// <returns></returns>
        public Message InsureTransfer( int srcUserID, string insurePass, int dstUserID, Int64 TradeScore, string clientIP, string note )
        {
            return treasureData.InsureTransfer( srcUserID, insurePass, dstUserID, TradeScore, clientIP, note );
        }

        /// <summary>
        /// 游戏记录
        /// </summary>
        /// <param name="whereQuery"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagerSet GetInsureTradeRecord( string whereQuery, int pageIndex, int pageSize )
        {
            return treasureData.GetInsureTradeRecord( whereQuery, pageIndex, pageSize );
        }

        #endregion

        #region 获取金币信息

        /// <summary>
        /// 根据用户ID得到金币信息
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public GameScoreInfo GetTreasureInfo2( int UserID )
        {
            if( treasureData == null ) return null;
            return treasureData.GetTreasureInfo2( UserID );
        }

        #endregion

        #region 财富排名

        /// <summary>
        /// 财富排名
        /// </summary>
        /// <returns></returns>
        public IList<GameScoreInfo> GetGameScoreInfoOrderByScore()
        {
            return treasureData.GetGameScoreInfoOrderByScore();
        }

        /// <summary>
        /// 财富排名
        /// </summary>
        /// <returns></returns>
        public DataSet GetScoreRanking( int num )
        {
            return treasureData.GetScoreRanking( num );
        }

        #endregion

        #region 货币信息

        /// <summary>
        /// 获取货币实体
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public UserCurrencyInfo GetUserCurrencyInfo(int userId)
        {
            return treasureData.GetUserCurrencyInfo(userId);
        }

        #endregion

        #region 会员操作

        /// <summary>
        /// 负分清零
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public Message ClearGameScore( int userID, string ip )
        {
            return treasureData.ClearGameScore( userID, ip );
        }

        /// <summary>
        /// 逃跑清零
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public Message ClearGameFlee( int userID, string ip )
        {
            return treasureData.ClearGameFlee( userID, ip );
        }

        #endregion

        #region 游戏记录

        /// <summary>
        /// 每桌游戏记录
        /// </summary>
        /// <param name="whereQuery"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagerSet GetDrawInfoRecord( string whereQuery, int pageIndex, int pageSize )
        {
            return treasureData.GetDrawInfoRecord( whereQuery, pageIndex, pageSize );
        }

        /// <summary>
        /// 每桌详细记录
        /// </summary>
        /// <param name="whereQuery"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagerSet GetDrawScoreRecord( string whereQuery, int pageIndex, int pageSize )
        {
            return treasureData.GetDrawScoreRecord( whereQuery, pageIndex, pageSize );
        }

        #endregion

        #region 公共

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pkey">排序或分组</param>
        /// <param name="whereQuery">查询条件</param>
        public PagerSet GetList( string tableName, int pageIndex, int pageSize, string pkey, string whereQuery )
        {
            return treasureData.GetList( tableName, pageIndex, pageSize, pkey, whereQuery );
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pkey">排序或分组</param>
        /// <param name="whereQuery">查询条件</param>
        /// <param name="whereQuery">字段</param>
        public PagerSet GetList( string tableName, int pageIndex, int pageSize, string pkey, string whereQuery, string fieldsList )
        {
            string[] fileds = fieldsList.Split( ',' );
            return treasureData.GetList( tableName, pageIndex, pageSize, pkey, whereQuery, fileds );
        }

        /// <summary>
        /// 根据sql语句获取数据
        /// </summary>
        /// <param name="sqlQuery"></param>
        /// <returns></returns>
        public DataSet GetDataSetByWhere( string sqlQuery )
        {
            return treasureData.GetDataSetByWhere( sqlQuery );
        }

        /// <summary>
        /// 根据sql获取实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public T GetEntity<T>( string commandText, List<DbParameter> parms )
        {
            return treasureData.GetEntity<T>( commandText, parms );
        }

        /// <summary>
        /// 根据sql获取实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public T GetEntity<T>( string commandText )
        {
            return treasureData.GetEntity<T>( commandText );
        }

        #endregion

        #region 任务系统

        /// <summary>
        /// 每日签到
        /// </summary>
        /// <param name="detialInfo"></param>
        /// <param name="receipt"></param>
        public Message WriteCheckIn( int userID, string strClientIP )
        {
            return treasureData.WriteCheckIn( userID, strClientIP );
        }
        #endregion

        #region 会员卡

        /// <summary>
        /// 获取会员卡
        /// </summary>
        /// <returns></returns>
        public DataSet GetMemberCardList()
        {
            return treasureData.GetMemberCardList();
        }

        /// <summary>
        /// 获取会员卡实体
        /// </summary>
        /// <returns></returns>
        public MemberCard GetMemberCard( int cardID )
        {
            return treasureData.GetMemberCard( cardID );
        }

        /// <summary>
        /// 购买会员卡，平台币兑换成金币
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="goodsID"></param>
        /// <param name="num"></param>
        /// <param name="insurePassword"></param>
        /// <returns></returns>
        public Message CurrencyExchange( int userID, int cardID, int num, string insurePassword, string IP )
        {
            return treasureData.CurrencyExchange( userID, cardID, num, insurePassword, IP );
        }
        #endregion

        #region 游戏信息

        /// <summary>
        /// 获取游戏总局排行
        /// </summary>
        /// <param name="number"></param>
        /// <param name="kindID"></param>
        /// <returns></returns>
        public IList<UserGameInfo> GetUserGameGrandTotalRank(int number, int dateID)
        {
            return treasureData.GetUserGameGrandTotalRank(number, dateID);
        }

        /// <summary>
        /// 获取游戏最大赢排行
        /// </summary>
        /// <param name="number"></param>
        /// <param name="kindID"></param>
        /// <returns></returns>
        public IList<UserGameInfo> GetUserGameWinMaxRank(int number, int dateID)
        {
            return treasureData.GetUserGameWinMaxRank(number, dateID);
        }

        #endregion

        #region 代理商管理

        /// <summary>
        /// 获取代理商下级玩家贡献税收分成金币
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public Int64 GetChildRevenueProvide(int userID)
        {
            return treasureData.GetChildRevenueProvide(userID);
        }

        /// <summary>
        /// 获取代理商下级玩家贡献的充值分成金币
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public Int64 GetChildPayProvide(int userID)
        {
            return treasureData.GetChildPayProvide(userID);
        }

        /// <summary>
        /// 获取代理分成详情
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public DataSet GetAgentFinance(int userID)
        {
            return treasureData.GetAgentFinance(userID);
        }

        /// <summary>
        /// 代理结算
        /// </summary>
        /// <param name="balance"></param>
        /// <param name="userID"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public Message GetAgentBalance(int balance, int userID, string ip)
        {
            return treasureData.GetAgentBalance(balance, userID, ip);
        }
        #endregion

        #region 转盘管理

        /// <summary>
        /// 获取转盘公共配置
        /// </summary>
        /// <returns></returns>
        public LotteryConfig GetLotteryConfig()
        {
            return treasureData.GetLotteryConfig();
        }

        /// <summary>
        /// 获取转盘配置
        /// </summary>
        /// <returns></returns>
        public IList<LotteryItem> GetLotteryItem()
        {
            return treasureData.GetLotteryItem();
        }

        /// <summary>
        /// 获取用户转盘信息
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Message GetLotteryUserInfo(int userID, string password)
        {
            return treasureData.GetLotteryUserInfo(userID, password);
        }

        /// <summary>
        /// 抽奖
        /// </summary>
        /// <param name="balance"></param>
        /// <param name="userID"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public Message GetLotteryStart(int userID, string password, string ip)
        {
            return treasureData.GetLotteryStart(userID, password, ip);
        }
        #endregion

        #region 分享

        /// <summary>
        /// 分享
        /// </summary>
        /// <param name="balance"></param>
        /// <param name="userID"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public Message SharePresent(int userID, string password, string machineID, string ip)
        {
            return treasureData.SharePresent(userID, password, machineID, ip);
        }
        #endregion

        #region 房卡
        /// <summary>
        /// 获取房卡信息
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public UserRoomCard GetUserRoomCard(int userID)
        {
            return treasureData.GetUserRoomCard(userID);
        }

        /// <summary>
        /// 获取房卡产品列表
        /// </summary>
        /// <returns></returns>
        public DataSet GetRoomCardConfigList()
        {
            return treasureData.GetRoomCardConfigList();
        }

        /// <summary>
        /// 获取房卡配置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RoomCardConfig GetRoomCardConfig(int id)
        {
            return treasureData.GetRoomCardConfig(id);
        }

        /// <summary>
        /// 获取最小房卡配置
        /// </summary>
        /// <returns></returns>
        public RoomCardConfig GetMinRoomCardConfig()
        {
            return treasureData.GetMinRoomCardConfig();
        }

        /// <summary>
        /// 购买房卡（代理）
        /// </summary>
        /// <returns></returns>
        public Message BuyRoomCard(int userId, string password, int configId, string clientIP)
        {
            return treasureData.BuyRoomCard(userId, password, configId, clientIP);
        }

        /// <summary>
        /// 购买房卡(普通玩家)
        /// </summary>
        /// <returns></returns>
        public Message BuyRoomCardGeneral(int userId, string password, int buynum, string clientIP, int typeId)
        {
            return treasureData.BuyRoomCardGeneral(userId, password, buynum, clientIP, typeId);
        }

        /// <summary>
        /// 房卡兑换（代理）
        /// </summary>
        /// <returns></returns>
        public Message ExchRoomCard(int userId, string password, int exchCount, string clientIP)
        {
            return treasureData.ExchRoomCard(userId, password, exchCount, clientIP);
        }

        /// <summary>
        /// 房卡兑换（普通玩家）
        /// </summary>
        /// <returns></returns>
        public Message ExchRoomCardGeneral(int userId, string password, int exchCount, string clientIP)
        {
            return treasureData.ExchRoomCardGeneral(userId, password, exchCount, clientIP);
        }

        /// <summary>
        /// 房卡赠送
        /// </summary>
        /// <returns></returns>
        public Message PresentRoomCard(int userId, string password, int presentCount, int gameId, string clientIP,string descript)
        {
            return treasureData.PresentRoomCard(userId, password, presentCount, gameId, clientIP, descript);
        }
        #endregion
    }
}
